﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WEALTH.Manager.UserControl
{
    public partial class cbxRole : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetRole();
            }
        }

        /// <summary>
        /// 用户角色复选框加载
        /// </summary>
        private void SetRole()
        {
            ExcuteDao userManage = new ExcuteDao();
            DataTable dt = userManage.Get_Role();
            this.cblRole.Items.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                ListItem li = new ListItem();
                li.Value = dr["Role_Code"].ToString();
                li.Text = dr["Role_Name"].ToString();
                this.cblRole.Items.Add(li);
            }

            if (Session["dtrole"] != null)
            {
                DataTable dtr = (DataTable)Session["dtrole"];
                for (int i = 0; i < dtr.Rows.Count; i++)
                {
                    foreach (ListItem ckRole in cblRole.Items)
                    {
                        if (ckRole.Value.Equals(dtr.Rows[i][0].ToString()))
                        {
                            ckRole.Selected = true;
                        }
                    }
                }
                Session["dtrole"] = null;
            }
        }
    }
}